// $_FILEHEADER_BEGIN ***************************
// 版权声明:Timer
// Copyright © 2015 - Timer All Rights Reserved
// 文件名称: ARBottomView.m
// 创建日期: 15/12/13
// 创 建 人: 甄鑫
// 文件说明: <#content#>
// $_FILEHEADER_END ******************************


#import "ARBottomView.h"
#import "NavHelper.h"
#import "ARRequestModel.h"
#import "IWillBorrowController.h"
#import "NavStatus.h"
#import "AlertDialogHelper.h"

@implementation ARBottomView
{
    __weak IBOutlet NSLayoutConstraint *changeBtnWidth;
    NSString *_showErrorMsg;

}
- (IBAction)borrowBtnClick:(id)sender {
    switch (self.baseType) {
        case 0://借入
        {
            [_textView resignFirstResponder];
            switch (self.pageType) {
                case 2:case 700://已满标  待审核放款
                {
                    
                }
                    break;
                case 4:case 3:case 9:case 13://还款中 还款审核中
                {
                    if (_showErrorMsg == nil) {
                            [self.delegate startPay];
                            [NavHelper gotoReimbursementVCWith:self.hopeID];
                    }else{
                        [AlertDialogHelper showToast:_showErrorMsg];
                    }
                }
                    break;
                case 5://已逾期 立即还款
                {
                    [self.delegate startPay];
                    [NavHelper gotoReimbursementVCWith:self.hopeID];
                }
                    break;
                case 7:case 6://已流标  重新借款
                {
                    IWillBorrowController * _vc = [[IWillBorrowController alloc]init];
                    [_vc againBorrow];
                    UINavigationController * nav = [[NavStatus sharedInstance]getCurVC].navigationController;
                    [_vc setHidesBottomBarWhenPushed:YES];
                    [nav pushViewController:_vc animated:YES];
                    
                }
                    break;
                default:
                    break;
            }
        }
            break;
        case 1://借出
        {
            switch (self.pageType) {
                case 1:case 0:case 11:case 12://借款中 立即出借
                {
                    [NavHelper gotoCanBorrowWithHopeId:self.hopeID];
                }
                    break;
                default:
                    break;
            }
        }
            break;
        case 2://理财 
        {
            switch (self.pageType) {
                case 1:case 0:case 11:case 12:
                {
                    [NavHelper gotoCanBorrowWithHopeId:self.hopeID];
                }
                    break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
}
- (IBAction)changeBtnClick:(id)sender {
    UIButton *button = (UIButton *)sender;
    if (button.selected == YES) {
        button.selected = NO;
        self.borrowBtn.hidden = YES;
    }else{
        button.selected = YES;
        self.borrowBtn.hidden = NO;
        [self endEditing:YES];
    }
}
- (IBAction)sendBtnClick:(id)sender {
    [[ ARRequestModel sharedInstance] sendPingLunWithText:self.textView.text andCB:^(id output) {
        if ([[NSString stringWithFormat:@"%@",[output objectForKey:@"result"]] integerValue]==1) {
            self.textView.text = @"";
            [self.textView resignFirstResponder];
            [self.delegate sendMsgSuccess];
        }
    }];
    
}
- (void)setDataWithDict:(NSDictionary *)output{
    self.borrowBtn.enabled = YES;
    if (self.pageType == 4||self.pageType == 3||self.pageType == 9||self.pageType == 13) {
        switch ([[NSString stringWithFormat:@"%@",output[@"installmentPaymentstatus"]] integerValue]) {
            case 2:
            {
                [_borrowBtn setTitle:@"已还款" forState:UIControlStateNormal];
                _showErrorMsg = @"已还款";
            }
                break;
            case 0:
            case 1:
            case 4:
            case 5:
            {
                [_borrowBtn setTitle:@"立即还款" forState:UIControlStateNormal];
                _showErrorMsg = nil;
            }
                break;
            case 6:
            case 16:
            {
                [_borrowBtn setTitle:@"还款处理中" forState:UIControlStateNormal];
                _showErrorMsg = @"还款处理中";
            }
                break;
            case 7:
            {
                [_borrowBtn setTitle:@"待审核还款" forState:UIControlStateNormal];
                _showErrorMsg = @"待审核还款";
            }
                break;
            case 100:
            {
                [_borrowBtn setTitle:@"立即还款" forState:UIControlStateNormal];
                _showErrorMsg = @"还款日前5天才可还款哦";
            }
                break;
            default:
                break;
        }

    }
}
@end
